package com.kgc.ssm.mapper;

import com.kgc.ssm.entity.Enquire;
import com.kgc.ssm.entity.EnquireExample;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.apache.ibatis.session.RowBounds;

public interface EnquireMapper {
    long countByExample(EnquireExample example);

    int deleteByExample(EnquireExample example);

    int deleteByPrimaryKey(Long id);

    int insert(Enquire row);

    int insertSelective(Enquire row);

    List<Enquire> selectByExampleWithRowbounds(EnquireExample example, RowBounds rowBounds);

    List<Enquire> selectByExample(EnquireExample example);

    Enquire selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("row") Enquire row, @Param("example") EnquireExample example);

    int updateByExample(@Param("row") Enquire row, @Param("example") EnquireExample example);

    int updateByPrimaryKeySelective(Enquire row);

    int updateByPrimaryKey(Enquire row);

    //连表查询QUOTE和ENQUIRE
    @Select("select * from ENQUIRE e,enquire_detail d,STOCK s where e.id=d.enquire_id and e.STOCK_ID=s.id")
    List<Map<String,Object>> getAllList();

    //表连接删除对应的id数据
    @Delete("delete from ENQUIRE where id=#{id}")
    int DeleteById(Integer id);
    @Delete("delete from QUOTE where enquire_id=#{id}")
    int DeleteQuoteById(Integer id);

    //表连接查询所有数据 ENQUIRE和QUOTE两表数据
    @Select("select * from " +
            "QUOTE q,ENQUIRE e,ENQUIRE_DETAIL d,QUOTE_DETAIL d2 " +
            "where q.enquire_id=e.id " +
            "and d2.quote_id=q.id " +
            "and d.ENQUIRE_ID=e.id " +
            "and e.id=#{id}")
    List<Map<String,Object>> selectAllQE(Integer id);

    @Select("select * from QUOTE_DETAIL d,QUOTE q " +
            "where d.quote_id=q.id " +
            "and enquire_id=#{id}")
    List<Map<String,Object>> selectQuoted(Integer id);

    @Select("select * from QUOTE where enquire_id=#{id}")
    List<Map<String,Object>> findAllQuote(Integer id);

    @Select("select * from ENQUIRE where id=#{id}")
    List<Map<String,Object>> findAllQE(Integer id);

    @Update("update ENQUIRE set " +
            "enquire_name=#{map.enquireName}," +
            "linkman=#{map.name}," +
            "address=#{map.address}," +
            "phone=#{map.phone}," +
            "fax=#{map.fax}," +
            "zip=#{map.zip}," +
            "email=#{map.email}," +
            "end_date=#{map.deadline}," +
            "REMARK=#{map.remark} " +
            "where id=#{map.id}")
    int updateEnquire(@Param("map") Map<String,Object> param);

    @Select("select * from ENQUIRE e,QUOTE q " +
            "where q.ENQUIRE_ID=e.id and " +
            "e.ENQUIRE_NUM=#{enquireNum};")
    Enquire selectByEnquire_Num(String enquireNum);





}